home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / Xform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-18  |  6.0 KB  |  221 lines

  1. /*
  2. //   (C) COPYRIGHT International Business Machines Corp. 1993
  3. //   All Rights Reserved
  4. //   Licensed Materials - Property of IBM
  5. //   US Government Users Restricted Rights - Use, duplication or
  6. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. //
  8.  
  9. //
  10. // Permission to use, copy, modify, and distribute this software and its
  11. // documentation for any purpose and without fee is hereby granted, provided
  12. // that the above copyright notice appear in all copies and that both that
  13. // copyright notice and this permission notice appear in supporting
  14. // documentation, and that the name of I.B.M. not be used in advertising
  15. // or publicity pertaining to distribution of the software without specific,
  16. // written prior permission. I.B.M. makes no representations about the
  17. // suitability of this software for any purpose.  It is provided "as is"
  18. // without express or implied warranty.
  19. //
  20. // I.B.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  21. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I.B.M.
  22. // BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24. // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  25. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26. //
  27. // Author:  John Spitzer, IBM AWS Graphics Systems (Austin)
  28. //
  29. */
  30.  
  31. #include "Xform.h"
  32. #include "XformX.h"
  33. #ifdef WIN32
  34. #include <windows.h>
  35. #include <gl\glaux.h>
  36. #elif __amigaos__
  37. #include <gl/glaux.h>
  38. #else
  39. #include "aux.h"
  40. #endif
  41.  
  42. #undef offset
  43. #define offset(v) offsetof(Transform,v)
  44.  
  45. static InfoItem TransformInfo[] = {
  46. #define INC_REASON INFO_ITEM_ARRAY
  47. #include "Xform.h"
  48. #undef INC_REASON
  49. };
  50. #include <malloc.h>
  51.  
  52. TransformPtr new_Transform()
  53. {
  54.     TransformPtr this = (TransformPtr)malloc(sizeof(Transform));
  55.     CheckMalloc(this);
  56.     new_Test((TestPtr)this);
  57.     SetDefaults((TestPtr)this, TransformInfo);
  58.     this->testType = TransformTest;
  59.     this->usecPixelPrint = "";
  60.     this->ratePixelPrint = "";
  61.     this->usecPrint = " microseconds per Transform";
  62.     this->ratePrint = " Transforms per second";
  63.     /* Set virtual functions */
  64.     this->SetState = Transform__SetState;
  65.     this->delete = delete_Transform;
  66.     this->Initialize = Transform__Initialize;
  67.     this->Cleanup = Transform__Cleanup;
  68.     this->SetExecuteFunc = Transform__SetExecuteFunc;
  69.     this->Copy = Transform__Copy;
  70.     this->PixelSize = Transform__Size;
  71.     return this;
  72. }
  73.  
  74. void delete_Transform(TestPtr thisTest)
  75. {
  76.     TransformPtr this = (TransformPtr)thisTest;
  77.     delete_Test(thisTest);
  78. }
  79.  
  80. TestPtr Transform__Copy(TestPtr thisTest)
  81. {
  82.     TransformPtr this = (TransformPtr)thisTest;
  83.     TransformPtr newTransform = new_Transform();
  84.     FreeStrings((TestPtr)newTransform);
  85.     *newTransform = *this;
  86.     CopyStrings((TestPtr)newTransform, (TestPtr)this);
  87.     return (TestPtr)newTransform;
  88. }
  89.  
  90. int Transform__SetState(TestPtr thisTest)
  91. {
  92.     TransformPtr this = (TransformPtr)thisTest;
  93.  
  94.     /* set parent GL state */
  95.     if (Test__SetState(thisTest) == -1) return -1;
  96.  
  97.     /* set own state */
  98.     if (this->pointDraw) {
  99.         glMatrixMode(GL_PROJECTION);
  100.         glLoadIdentity();
  101.         glMatrixMode(GL_MODELVIEW);
  102.         glLoadIdentity();
  103.     }
  104.  
  105.     return 0;
  106. }
  107.  
  108. void Transform__Initialize(TestPtr thisTest)
  109. {
  110.     TransformPtr this = (TransformPtr)thisTest;
  111.     int i;
  112.     int loops = this->loopUnroll;
  113.     GLfloat *ptr;
  114.     GLfloat fraction;
  115.  
  116.  
  117.     this->numObjects = 1;
  118.     /* Set the transform data */
  119.     /* Just allocate the maximum amount of memory that's going to be */
  120.     /* used, it's not a lot.                                         */
  121.     this->transformData = (GLfloat*)malloc(sizeof(GLfloat) * 6 * 8);
  122.     ptr = this->transformData;
  123.     switch (this->transformType) {
  124.     case Translate:
  125.     case Scale:
  126.         for (i=0; i<loops; i++) {
  127.           if(loops==1)
  128.         fraction = (GLfloat)i/(GLfloat)(loops+1);
  129.           else
  130.         fraction = (GLfloat)i/(GLfloat)(loops-1);
  131.  
  132.         *ptr++ = .5 + .1 * fraction;
  133.         *ptr++ = .5 + .1 * fraction;
  134.         *ptr++ = .5 + .1 * fraction;
  135.             }
  136.         break;
  137.     case Rotate:
  138.         for (i=0; i<loops; i++) {
  139.           if(loops==1)
  140.         fraction = (GLfloat)i/(GLfloat)(loops+1);
  141.           else
  142.         fraction = (GLfloat)i/(GLfloat)(loops-1);
  143.  
  144.         *ptr++ = 10. + 5. * fraction;
  145.         *ptr++ = .5 + .1 * fraction;
  146.         *ptr++ = .5 + .1 * fraction;
  147.         *ptr++ = .5 + .1 * fraction;
  148.         }
  149.         break;
  150.     case Perspective:
  151.         for (i=0; i<loops; i++) {
  152.           if(loops==1)
  153.         fraction = (GLfloat)i/(GLfloat)(loops+1);
  154.           else
  155.         fraction = (GLfloat)i/(GLfloat)(loops-1);
  156.         *ptr++ = 1.0;
  157.         *ptr++ = .5 + .5 * fraction;
  158.         *ptr++ = 50. + 50. * fraction;
  159.         }
  160.         break;
  161.     case Ortho:
  162.     case Frustum:
  163.         for (i=0; i<loops; i++) {
  164.           if(loops==1)
  165.         fraction = (GLfloat)i/(GLfloat)(loops+1);
  166.           else
  167.         fraction = (GLfloat)i/(GLfloat)(loops-1);
  168.  
  169.         *ptr++ = -.5 - .5 * fraction;
  170.         *ptr++ =  .5 + .5 * fraction;
  171.         *ptr++ = -.5 - .5 * fraction;
  172.         *ptr++ =  .5 + .5 * fraction;
  173.         *ptr++ =  .5 + .5 * fraction;
  174.         *ptr++ = 50. + 50. * fraction;
  175.         }
  176.         break;
  177.     case Ortho2:
  178.         for (i=0; i<loops; i++) {
  179.           if(loops==1)
  180.         fraction = (GLfloat)i/(GLfloat)(loops+1);
  181.           else
  182.         fraction = (GLfloat)i/(GLfloat)(loops-1);
  183.  
  184.         *ptr++ = -.5 - .5 * fraction;
  185.         *ptr++ =  .5 + .5 * fraction;
  186.         *ptr++ = -.5 - .5 * fraction;
  187.         *ptr++ =  .5 + .5 * fraction;
  188.         }
  189.         break;
  190.   }
  191. }
  192.  
  193. void Transform__Cleanup(TestPtr thisTest)
  194. {
  195.     TransformPtr this = (TransformPtr)thisTest;
  196.  
  197.     if(this->transformData)
  198.       free(this->transformData);
  199. }
  200.  
  201. void Transform__SetExecuteFunc(TestPtr thisTest)
  202. {
  203.     TransformPtr this = (TransformPtr)thisTest;
  204.     TransformFunc function;
  205.  
  206.     function.word = 0;
  207.  
  208.     function.bits.transform = this->transformType;
  209.     function.bits.pushPop = this->pushPop;
  210.     function.bits.pointDraw = this->pointDraw;
  211.     function.bits.functionPtrs = this->loopFuncPtrs;
  212.     function.bits.unrollAmount  = this->loopUnroll - 1;
  213.  
  214.     this->Execute = TransformExecuteTable[function.word];
  215. }
  216.  
  217. float Transform__Size(TestPtr thisTest)
  218. {
  219.     return 0.;
  220. }
  221.